package com.apes.scm.account.account.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.Product;
import com.apes.scm.masterdata.stock.model.Location;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.Date;

/**
 * Created by LJP on 2021-10-13 10:23
 * 安全库存变动记录
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = SafetyStockLogger.CONST_TABLE_NAME)
public class SafetyStockLogger extends Model {
    public static final String CONST_TABLE_NAME = "acc_safety_stock_logger";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "安全库存变动记录",padding = 8)
    @Comment("编码")
    private Long id;  //编码

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "LOCATION_ID", referencedColumnName = "id", nullable = false)
    @Comment("仓库库区")
    private Location location;  //仓库库区

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "PRODUCT_ID", referencedColumnName = "id", nullable = false)
    @Comment("商品编码")
    private Product product;   //商品编码

    @Column(name = "THE_MAX_QTY", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    @Comment("最高限量")
    private double theMaxQty = 0.0;  //最高限量

    @Column(name = "THE_MIN_QTY", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    @Comment("最低限量")
    private double theMinQty = 0.0;  //最低限量

    @Column(name = "SAFETY_STOCK_QTY", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    @Comment("安全库存")
    private double safetyStockQty = 0.0;

    @Column(name = "LAST_THE_MAX_QTY", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    @Comment("原最高限量")
    private double lastTheMaxQty = 0.0;  //原最高限量

    @Column(name = "LAST_THE_MIN_QTY", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    @Comment("原最低限量")
    private double lastTheMinQty = 0.0;  //原最低限量

    @Column(name = "LAST_SAFETY_STOCK_QTY", nullable = false, columnDefinition = "NUMBER(16,4) DEFAULT 0")
    @Comment("原安全库存")
    private double lastSafetyStockQty = 0.0;

    @Column(name = "CHANGE_DATE")
    @Comment("变动日期")
    private Date changeDate;  //变动日期

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "CHANGE_UID", referencedColumnName = "id")
    @Comment("操作员")
    private PartyRole changeUid;
}
